<template>
  <ContainerGroup>
    <Container style="margin-bottom: 10px">
      <FilterForm
        ref="filterForm"
        :is-show-btn="false"
        :elements="filterElements"
      >
        <!-- <Button
          style="display: inline-block; margin-right: 10px"
          @click="handleImplement(1)"
          >收入检查</Button
        >
        <Button
          style="display: inline-block; margin-right: 10px"
          @click="handleImplement(2)"
          >成本检查</Button
        > -->
        <Button
          style="display: inline-block"
          @click="handleResult"
        >开始采集</Button>
      </FilterForm>
    </Container>
    <Container
      v-loading="tableLoading"
      height="fill"
      :scroll-y="true"
      display="flexY"
    >
      <div class="cj-box">
        <div class="box">
          <div style="text-align: center; margin-top: 30px">
            <img src="@/assets/image/kaishi.png" alt="">
          </div>

          <div class="textStyle">开始</div>
        </div>
        <div>
          <img src="@/assets/image/jiantou.png" alt="">
        </div>
        <div class="box">
          <div style="text-align: center; margin-top: 30px">
            <img src="@/assets/image/cbcj.png" alt="">
          </div>

          <div class="textStyle">收入采集</div>
        </div>
        <div>
          <img src="@/assets/image/jiantou.png" alt="">
        </div>

        <div class="box">
          <div style="text-align: center; margin-top: 30px">
            <img src="@/assets/image/srcj.png" alt="">
          </div>

          <div class="textStyle">成本采集</div>
        </div>
        <div>
          <img src="@/assets/image/jiantou.png" alt="">
        </div>

        <div class="box">
          <div style="text-align: center; margin-top: 30px">
            <img src="@/assets/image/wancheng.png" alt="">
          </div>

          <div class="textStyle">完成</div>
        </div>
      </div>
      <!-- <el-divider content-position="left">未完整分摊科室</el-divider> -->
      <el-table
        v-if="false"
        ref="tableref"
        v-loading="tableLoading"
        :data="tableData"
        border
        :header-cell-style="{ background: '#fafafa', borderColor: '#e7ecf8' }"
        header-row-class-name="ck-table-header"
        row-class-name="ck-table-row"
        size="small"
        height="100%"
      >
        <el-table-column label="基本信息" align="center" width="270">
          <el-table-column
            align="center"
            type="index"
            label="序号"
            width="50"
          />
          <el-table-column prop="deptCode" label="科室代码" width="80">
            <template slot-scope="scope">
              <div class="text-btn">
                {{ scope.row.deptCode }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="deptName" label="科室名称" width="140" />
        </el-table-column>
        <el-table-column label="人员费用" align="center">
          <el-table-column
            prop="directPersonnel"
            label="直接成本"
            width="140"
          />
          <el-table-column
            prop="indirectPersonnel"
            label="间接成本"
            width="140"
          />
          <el-table-column
            prop="totalPersonnel"
            label="全成本"
            width="140"
          />
        </el-table-column>
        <el-table-column label="药品费用" align="center">
          <el-table-column prop="directDrug" label="直接成本" width="140" />
          <el-table-column prop="indirectDrug" label="间接成本" width="140" />
          <el-table-column
            prop="totalDrug"
            label="全成本"
            width="140"
          />
        </el-table-column>
        <el-table-column label="卫生材料费用" align="center">
          <el-table-column
            prop="directSanitaryMaterials"
            label="直接成本"
            width="140"
          />
          <el-table-column
            prop="indirectSanitaryMaterials"
            label="间接成本"
            width="140"
          />
          <el-table-column
            prop="totalSanitaryMaterials"
            label="全成本"
            width="140"
          />
        </el-table-column>
        <el-table-column label="固定资产折旧费" align="center">
          <el-table-column prop="directFixed" label="直接成本" width="140" />
          <el-table-column prop="indirectFixed" label="间接成本" width="140" />
          <el-table-column
            prop="totalFixed"
            label="全成本"
            width="140"
          />
        </el-table-column>
        <el-table-column label="无形资产折旧费" align="center">
          <el-table-column
            prop="directIntangible"
            label="直接成本"
            width="140"
          />
          <el-table-column
            prop="indirectIntangible"
            label="间接成本"
            width="140"
          />
          <el-table-column
            prop="totalIntangible"
            label="全成本"
            width="140"
          />
        </el-table-column>
        <el-table-column label="提取医疗风险基金" align="center">
          <el-table-column prop="directRisk" label="直接成本" width="140" />
          <el-table-column prop="indirectRisk" label="间接成本" width="140" />
          <el-table-column
            prop="totalRisk"
            label="全成本"
            width="140"
          />
        </el-table-column>
        <el-table-column label="其他费用" align="center">
          <el-table-column prop="directOther" label="直接成本" width="140" />
          <el-table-column prop="indirectOther" label="间接成本" width="140" />
          <el-table-column
            prop="totalOther"
            label="全成本"
            width="140"
          />
        </el-table-column>
        <el-table-column label="合计" align="center" width="420">
          <el-table-column prop="directSum" label="直接成本" width="140" />
          <el-table-column prop="indirectSum" label="间接成本" width="140" />
          <el-table-column
            prop="totalSum"
            label="全成本"
            width="140"
          />
        </el-table-column>
      </el-table>
      <Dialog
        :title="title"
        :visible="modalVisable"
        :footer-btns="[
          {
            text: '取消',
            type: 'info',
            trigger: 'cancel',
          }
        ]"
        @cancel="modalVisable = false"
      >
        <div class="list-box">
          <div v-for="(item,index) in checkResult" :key="index" class="list-item">{{ item }}</div>
        </div>
      </Dialog>
    </Container>
  </ContainerGroup>
</template>

<script>
import { insertCoefficient, quickAmortization, insertBaseCost, insertBaseInCome, getCheckIncome } from '@/utils/apis/dataAccount'
import { listAmortizationDataByPDeptCode } from '@/utils/apis/report'
import { DateDTO } from '@/utils/quickAmortization'
export default {
  name: 'InOutCaiji', // 科室-工资对应
  components: {},
  data() {
    return {
      modalVisable: false,
      title: '',
      newParamList: {},
      tableData: [],
      tableLoading: false,
      schools: [],
      filterElements: [
        {
          key: 'yearMonth',
          type: 'date-picker',
          label: '年/月',
          mode: 'month',
          type: 'date-picker',
          format: 'yyyy-MM',
          value: this.$util.currentDate(),
          width: 300
        }
        // {
        //   filterable: true,
        //   clearable: true,
        //   key: "billDeptCode",
        //   type: "Select",
        //   label: "院区",
        //   value: "",
        //   itemLabel: "deptName",
        //   itemValue: "deptCode",
        //   width: 210,
        //   multiple: true,
        //   collapseTags: true,
        //   options: [],
        // },
      ],
      checkResult: []
    }
  },
  created() {},
  mounted() {},
  methods: {
    handleSearch(value) {
      this.newParamList = value
      this.getData()
    },
    handleImplement(type) { // 检查
      const date = this.$refs.filterForm.getParms()?.yearMonth
      const currentYear = new Date(date).getFullYear()
      const currentMonth = new Date(date).getMonth() + 1
      const param = {
        sysid: type === 1 ? 'Income' : 'Cost',
        month: this.formatNumber(currentMonth),
        year: currentYear
      }
      this.checkResult = []
      getCheckIncome(param).then((res) => {
        console.log('----------------', res.data)
        if (res.data?.length > 0) {
          this.title = type === 1 ? '收入检查' : '成本检查'
          this.checkResult = res.data
          this.modalVisable = true
        } else {
          this.$message.success('查无异常数据')
        }
      })
    },
    handleResult() {
      // 生成结果
      const date = this.$refs.filterForm.getParms()?.yearMonth
      const currentYear = new Date(date).getFullYear()
      const currentMonth = new Date(date).getMonth() + 1

      const param = {
        // endTime: `${currentYear}-${currentMonth}-${this.formatNumber(
        //   new Date(currentYear, currentMonth, 0).getDate()
        // )} 23:59:59`,
        month: this.formatNumber(currentMonth),
        // starTime: `${currentYear}-${currentMonth}-${this.formatNumber(
        //   new Date(currentYear, currentMonth, 1).getDate()
        // )} 00:00:00`,
        year: currentYear
      }
      this.tableLoading = true
      insertBaseCost(param).then((res) => {
        this.tableLoading = false
        if (res.data.code === 200) {
          this.$message.success(res.data.message)
        } else {
          this.$message.error(res.data.message)
        }
      })
      insertBaseInCome(param).then((res) => {
        if (res.data.code === 200) {
          this.$message.success(res.data.message)
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    formatNumber(n) {
      n = n.toString()
      return n[1] ? n : `0${n}`
    },
    getData() {
      this.$nextTick(() => {
        const date = this.newParamList.yearMonth
        const currentYear = new Date(date).getFullYear()
        const currentMonth = new Date(date).getMonth() + 1
        const param = {
          month: currentMonth,
          yard: '1',
          year: currentYear
        }
        // this.tableLoading = true
        listAmortizationDataByPDeptCode(param, 'BBBBBBBBBB').then((res) => {
          // this.tableLoading = false
          if (res.data.code === 200) {
            this.tableData = res.data.data
          }
        })
      })
    },
    resetForm() {},
    searchSubmit() {},
    createNewData() {},
    // 分页
    handleSizeChange(val) {
      this.pageSize = val
      this._getData()
    },
    handleCurrentChange(val) {
      this.pageNum = val
      this._getData()
    }
  }
}
</script>

<style lang="less" scoped>
.list-box{
  .list-item{
    margin-bottom: 10px;
  }
}
.cj-box{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-left: 30px;
  margin-right: 30px;
  margin-bottom: 15px;
  height: 100%;
}
/deep/.el-divider__text {
  font-size: 15px;
  font-weight: bold;
}
.el-table--mini,
.el-table--small,
.el-table__expand-icon {
  font-size: 14px !important;
}

.ck-table-header {
  th {
    background: #fafafa !important;
    height: 48px;
    color: #555555 !important;
  }
}
.pagenation-box {
  display: flex;
  padding-top: 2px;
  justify-content: flex-end;
}

.box {
  width: 220px;
  height: 200px;
  opacity: 1;
  background: #f0f2f5;
  border-radius: 15px;
}

.textStyle {
  text-align: center;
  margin-top: 20px;
  height: 19px;
  opacity: 1;
  font-size: 20px;
  font-weight: 400;
  color: #555555;
}
</style>
